package com.yuexun.dhdoctor.widget.model;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yuexun.dhdoctor.R;
import com.yuexun.dhdoctor.base.bean.model.HelpFileData;
import com.yuexun.dhdoctor.config.AppConfig;

import org.kymjs.kjframe.utils.PreferenceHelper;

import java.util.ArrayList;

/**
 * Created by chenss on 2017/7/31 0031.
 */

public class CreateDictionaryView {

    Context context;
    ArrayList<HelpFileData> dtlList;//配置详情列表

    public CreateDictionaryView(Context context, ArrayList<HelpFileData> dtlList) {
        this.context = context;
        this.dtlList = dtlList;
    }

    /**
     * 方法描述：添加文本布局
     *
     * @param fileData
     * @return
     */
    public View createDictionaryView(final String num, final HelpFileData fileData) {
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        View view = null;

        view = LayoutInflater.from(context).inflate(R.layout.add_item_txt_layout_01, null);//也可以从XML中加载布局
        view.setLayoutParams(lp);//设置布局参数

        TextView txt_title = (TextView) view.findViewById(R.id.txt_title);
        final EditText txt_content = (EditText) view.findViewById(R.id.txt_content);

        fileData.setShowType(fileData.getShowType());

        txt_title.setText(fileData.getDtlName());

        txt_content.setHint("请输入" + fileData.getDtlName());
        txt_content.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                fileData.setDtlValue(txt_content.getText().toString());
            }
        });

        //1 工号 2姓名  3科室
        switch (num) {
            case "1":
                txt_content.setText(PreferenceHelper.readString(context, AppConfig.USER_INFO, AppConfig.JOB_ID));
                break;
            case "2":
                txt_content.setText(PreferenceHelper.readString(context, AppConfig.USER_INFO, AppConfig.USER_NAME));
                break;
            case "3":
                txt_content.setText(PreferenceHelper.readString(context, AppConfig.USER_INFO, AppConfig.DEPARTMENTNAME));
                break;
        }
        txt_content.setFocusable(false);
        txt_content.setFocusableInTouchMode(false);

        dtlList.add(fileData);
        return view;
    }
}
